package com.atguigu.yygh.hosp.controller.user;

import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.hosp.service.DepartmentService;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.DepartmentVo;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author luoyin
 * @Date 13:49 2022/9/30
 **/
@RestController
@RequestMapping("/user/hosp")
public class UserHospitalController {

    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;
    @GetMapping("/{pageNum}/{pageSize}")
    public R page(@PathVariable Integer pageNum , @PathVariable Integer pageSize , HospitalQueryVo hospitalQueryVo ){

        Page<Hospital> page = hospitalService.selectPage(pageNum, pageSize, hospitalQueryVo);
        return R.ok().data("list",page.getContent());
    }

    @GetMapping("/{hosname}")
    public R findByHosname(@PathVariable String hosname){

        List<Hospital> list = hospitalService.findByHosname(hosname);
        return R.ok().data("list",list);
    }

    //医院详情
    @GetMapping("/show/{hoscode}")
    public R show(@PathVariable String hoscode){
        Hospital hospital = hospitalService.findByHoscode(hoscode);
        return R.ok().data("hospital",hospital);
    }

    //大科室及小科室
    @GetMapping("/findDepartment/{hoscode}")
    public R findDepartment(@PathVariable String hoscode){
        List<DepartmentVo> list = departmentService.getDeptByHoscode(hoscode);
        return R.ok().data("list",list);
    }
}
